import Vue from 'vue'
import VueRouter from 'vue-router'
import GoodList from '../views/GoodList.vue'
import GoodDetail from '../views/GoodDetail.vue'

Vue.use(VueRouter)

const routes = [
  {
    path: '/',
    name: 'GoodList',
    component: GoodList,
    meta:{
      title:'商品列表'
    }
  },
  {
    path: '/detail',
    name: 'GoodDetail',
    component: GoodDetail,
    meta:{
      title:'商品详情'
    }
  }
]

const router = new VueRouter({
  routes
})

// 解决Vue-Router升级导致的Uncaught(in promise) navigation guard问题
const originalPush = VueRouter.prototype.push
VueRouter.prototype.push = function push (location, onResolve, onReject) {
  if (onResolve || onReject) return originalPush.call(this, location, onResolve, onReject)
  return originalPush.call(this, location).catch(err => err)
}

router.beforeEach((to,from,next)=>{
  document.title = to.meta.title


  next()
})

export default router
